/***
 * @Author: Xavier 1305433186@qq.com
 * @Date: 2024-08-09 15:13:42
 * @LastEditors: Xavier 1305433186@qq.com
 * @LastEditTime: 2024-08-14 17:25:08
 * @FilePath: \JS32T031_SDK\User\433_decoding\433_software_decoding.h
 * @Description:
 * @
 * @STAYTRUE (c) 2024 by ${Xavier}, All Rights Reserved.
 */

#ifndef _433_SOFTWARE_DECODING_
#define _433_SOFTWARE_DECODING_
#include "typedef.h"
/* 根据  任务时间 设定 */
#define WIRELESS_433_TASK_TIMESTAMP 100 // 单位

/* 以下参数根据 厂家 提供参数填写，不建议修改*/
#define LOW_LEVEL_MIN_TIME 200 / WIRELESS_433_TASK_TIMESTAMP	  // 0.2ms
#define LOW_LEVEL_MAX_TIME 600 / WIRELESS_433_TASK_TIMESTAMP	  // 0.6ms
#define HIGT_LEVEL_MIN_TIME 800 / WIRELESS_433_TASK_TIMESTAMP	  // 0.8ms
#define HIGT_LEVEL_MAX_TIME 1400 / WIRELESS_433_TASK_TIMESTAMP	  // 1.4ms
#define START_SIGNAL_MIN_TIME 8000 / WIRELESS_433_TASK_TIMESTAMP  // 8ms
#define START_SIGNAL_MAX_TIME 15000 / WIRELESS_433_TASK_TIMESTAMP // 15ms

// 遥控解码 字节数  不能大于4
#define WIRELESS_433_BYTE 3
/**
 * @brief 获取IO口回调函数原型
 */
typedef unsigned char (*wireless_433_get_io_cb_t)(void);

typedef struct
{
	wireless_433_get_io_cb_t get_io;
} wireless_433_config_t;
typedef struct
{
	unsigned char ir_time; // 时间计时  单位 :时间戳  WIRELESS_433_TASK_TIMESTAMP
	unsigned char low_time;
	unsigned char higt_time;
	bool low_count_time_sign;			   // 计时标志
	bool higt_count_time_sign;			   // 计时标志
	bool ir_stok;						   // 起始信号标志
	bool decryption_successful;			   // 起始信号标志
	unsigned char raw_data_len;			   // 原始数据
	unsigned long raw_data;				   // 原始数据
	unsigned long raw_data_last;		   // 原始数据 上一包
	unsigned long press_count;			   // 原始数据 上一包  同一个按键 长按 计数
	unsigned char byte[WIRELESS_433_BYTE]; // 遥控码
} wireless_433_data_t;					   /*发送环形缓冲区*/

void decode_433_io_init(wireless_433_config_t *p_config_t);
unsigned char get_433_key_stroke(unsigned char *key_stroke);
void decode_433(void);
#endif
